#include "delay.h"
#include "sys.h"
#include "timer.h"
#include "adc.h"
#include "usart.h"	
	
int main(void)
{		
	u16 adc=0;
	u32 arr;
	delay_init();	    	
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); 	
	TIM1_PWM_Init(4096,0);	
	Adc_Init();
	MotoInit();
	
	while(1)
	{
		adc=Get_Adc();	 
		if(adc<2048)
		{			
			arr=adc+2048;
			TIM_SetCompare2(TIM1,arr);
			TOUT=0;
		} 
		else
		{
			arr=adc-2048;
			TIM_SetCompare2(TIM1,arr);
			TOUT=1;		
		}	   
	}	 
}

